import java.util.Arrays;

public class PrrWay {

    /**
     * 2.删除数据
     * contains模糊查询
     * equals比较全部
     */
    public boolean del(personArr[] per, String name) {
        for (int i = 0; i < per.length; i++) {
            if (per[i].name.equals(name)) {
                for (int j = i; j < per.length - 1; j++) {
                    per[j] = per[j + 1];
                }
                per[per.length - 1] = null;
                return true;
            }
        }
        return false;
    }

    /**
     * 3.改
     */
    public int alter(personArr[] per, String name) {
        for (int i = 0; i < per.length; i++) {
            if (per[i].name.equals(name)) {
                return i;//找到就返回找到的类数组的下标
            }
        }
        return -1;//没找到就返回-1，让主程序判断
    }

    ////4.查询所有

    public void traversal(personArr[] per) {
        for (int i = 0; i < per.length && per[i] != null; i++) {
            per[i].get();
        }
    }

    /**
     * 5.根据姓名查询
     * contains模糊查询
     */
    public String[] check(personArr[] per, String name) {
        String[] sub = new String[0];
        int j = 0;
        for (int i = 0; i < per.length; i++) {
            if (per[i].name.contains(name)) {
                sub = Arrays.copyOf(sub, sub.length + 1);
                sub[j] = per[i].name;
                j++;
            }
        }
        return sub;
    }

}
